﻿using UnityEngine;
using System.Collections;

public class MoveController : MonoBehaviour
{
    public Character character;

    void OnEnable()
    {
        EasyJoystick.On_JoystickMove += OnJoystickMove;
        EasyJoystick.On_JoystickMoveEnd += OnJoystickMoveEnd;
    }

    void OnDisable()
    {
        EasyJoystick.On_JoystickMove -= OnJoystickMove;
        EasyJoystick.On_JoystickMoveEnd -= OnJoystickMoveEnd;
    }

    void OnDestroy()
    {
        EasyJoystick.On_JoystickMove -= OnJoystickMove;
        EasyJoystick.On_JoystickMoveEnd -= OnJoystickMoveEnd;
    }


    void OnJoystickMoveEnd(MovingJoystick move)
    {
        if (move.joystickName == "MoveJoystick" && character != null)
        {
            character.joyPositionX = 0;
            character.joyPositionY = 0;
        }
    }
    void OnJoystickMove(MovingJoystick move)
    {
        if (move.joystickName != "MoveJoystick" || character == null)
        {
            return;
        }

        character.joyPositionX = move.joystickAxis.x;
        character.joyPositionY = move.joystickAxis.y;
    }
}
